package com.ss.android.article.common.share.helper;

import android.content.Context;
import android.text.TextUtils;

import com.a.a.NightMode;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.account.Spipe;
import com.ss.android.action.ArticleActionHelper;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.share.abs.AbsShareHelper;
import com.ss.android.article.common.share.log.ShareRespEntry;
import com.ss.android.article.common.share.interf.IShareArticleBean;
import com.ss.android.article.common.share.interf.IShareDataBean;
import com.ss.android.article.common.share.interf.IShareDataHook;
import com.ss.android.article.common.share.interf.IShareEntryItemBean;
import com.ss.android.article.common.share.interf.IShareEssayBean;
import com.ss.android.article.common.share.interf.j;
import com.ss.android.article.common.share.interf.k;
import com.ss.android.article.common.share.interf.ISharePostBean;
import com.ss.android.article.common.share.interf.IShareUpdateItemBean;
import com.ss.android.article.share.d.e;
import com.ss.android.article.share.entity.ShareAction;
import com.ss.android.article.share.entity.ShareImageBean;
import com.ss.android.common.app.AbsApplication;
import com.ss.android.common.util.UrlBuilder;
import com.ss.android.image.model.ImageInfo;
import com.ss.android.model.AbsArticle;

import org.json.JSONException;
import org.json.JSONObject;

import inline.ImageUtils;
import inline.ShareDemo;

public final class CommonWXShareHelper extends AbsShareHelper {
    public ArticleActionHelper f;
    public String g;
    public int h;
    private Context i;
    private boolean j;
    private String k;
    private String l;
    private String m;
    private String n;
    private String o;
    private boolean p;
    private boolean q;
    private static CommonWXShareHelper r;
    private static final Object s;
    private int t;
    private IShareDataHook u;

    static {
        s = new Object();
    }

    private CommonWXShareHelper(Context arg3) {
        this.m = "";
        this.t = 0;
        this.j = true;
        this.i = arg3.getApplicationContext();
        if(AbsApplication.getCtx() != null && !TextUtils.equals(arg3.getPackageName(), AbsApplication.getCtx().getPackageName())) {
            this.i = AbsApplication.getCtx();
        }
    }

    public static CommonWXShareHelper getInstance(Context arg2, IShareDataHook arg3, int arg4) {
        Object v1 = s;
        synchronized (v1){
            if(r == null) {
                r = new CommonWXShareHelper(arg2);
            }

            if(arg3 == null) {
                r.t = arg4;
                return r;
            }
        }

        r.u = arg3;
        r.t = arg4;
        return r;
    }

    public final boolean a(IShareDataBean arg11, Object[] arg12) {
        e v7_1;
        String v6_2;
        String v5;
        String v0_1;
        String v1;
        String v2;
        boolean v0;
        NightMode v8 = null;
        int v7 = R.string.app_name;
        if(arg12.length > 0 && ((arg12[0] instanceof Integer))) {
            this.t = ((Integer)arg12[0]).intValue();
        }

        int v3 = this.t;
        if(this.i == null || this.u == null) {
            v0 = false;
        }
        else {
            if(!this.a()) {
                UIUtils.showImageToast(this.i, R.drawable.close_popup_textpage, R.string.toast_weixin_not_install);
            }
            else if((arg11 instanceof IShareArticleBean)) {
                v0 = this.a(((IShareArticleBean)arg11), v3, this.f);
                return v0;
            }
            else if((arg11 instanceof k)) {
                return this.a(((k)arg11), v3);
            }
            else if((arg11 instanceof IShareUpdateItemBean)) {
                return this.b(((IShareUpdateItemBean)arg11), v3);
            }
            else if((arg11 instanceof IShareEntryItemBean)) {
                return this.b(((IShareEntryItemBean)arg11), v3);
            }
            else if((arg11 instanceof IShareEssayBean)) {
                return this.a(((IShareEssayBean)arg11), v3, this.f);
            }
            else {
                if((arg11 instanceof ISharePostBean)) {
                    v0 = this.b(((ISharePostBean)arg11), v3);
                }
                else if((arg11 instanceof com.ss.android.article.common.share.interf.c)) {
                    v2 = ((com.ss.android.article.common.share.interf.c)arg11).b();
                    v1 = ((com.ss.android.article.common.share.interf.c)arg11).c();
                    v0_1 = v3 == 1 ? v1 : ((com.ss.android.article.common.share.interf.c)arg11).d();
                    v5 = ((com.ss.android.article.common.share.interf.c)arg11).e();
                    v2 = v3 == 1 ? ShareDemo.a(v2, "weixin_moments", "weixin_moments") : ShareDemo.a(v2, "weixin", "weixin");
                    ((AbsShareHelper)this).mShareSource = 212;
                    ShareRespEntry v6 = new ShareRespEntry(((AbsShareHelper)this).mShareSource, v3);
                    entry = v6;
                    v6.l = ((com.ss.android.article.common.share.interf.c)arg11).a();
                    e v6_1 = new e(this.i, this.u.isShareExtendedObjectEnabled());
                    ShareAction v3_1 = v3 == 0 ? ShareAction.wx : ShareAction.wxtimeline;
                    v0 = v6_1.a(v3_1).b(v0_1).a(v1).c(v2).a(new ShareImageBean(v5, false)).a();
                }
                else {
                    if((arg11 instanceof com.ss.android.article.common.share.interf.e)) {
                        v5 = ((com.ss.android.article.common.share.interf.e)arg11).getShareUrl();
                        Context v1_1 = this.i;
                        if(!android.support.design.a.isTextEmpty(((com.ss.android.article.common.share.interf.e)arg11).b())) {
                            v0_1 = ((com.ss.android.article.common.share.interf.e)arg11).b();
                        }
                        else {
                            v0_1 = ((com.ss.android.article.common.share.interf.e)arg11).a();
                            if(android.support.design.a.isTextEmpty(v0_1)) {
                                v0_1 = v1_1.getString(v7);
                            }
                        }

                        v1 = !android.support.design.a.isTextEmpty(((com.ss.android.article.common.share.interf.e)arg11).c()) ? ((com.ss.android.article.common.share.interf.e)arg11).c() : "";
                        v6_2 = ((com.ss.android.article.common.share.interf.e)arg11).e();
                        ((AbsShareHelper)this).mShareSource = 209;
                        ShareRespEntry v2_1 = new ShareRespEntry(((AbsShareHelper)this).mShareSource, v3);
                        entry = v2_1;
                        v2_1.m = ((com.ss.android.article.common.share.interf.e)arg11).d();
                        v7_1 = new e(this.i, false);
                        ShareAction v2_2 = v3 == 0 ? ShareAction.wx : ShareAction.wxtimeline;
                        e v2_3 = v7_1.a(v2_2).b(v1);
                        if(v3 != 0) {
                            v0_1 = v1;
                        }

                        return v2_3.a(v0_1).c(v5).a(new ShareImageBean(v6_2, false)).a();
                    }

                    if(!(arg11 instanceof j)) {
                       return false;
                    }

                    v5 = ((j)arg11).getShareUrl();
                    v0_1 = ((j)arg11).c();
                    if(android.support.design.a.isTextEmpty(v0_1)) {
                        v0_1 = this.i.getString(v7);
                    }

                    v2 = ((j)arg11).a();
                    v6_2 = ((j)arg11).b();
                    com.ss.android.article.share.d.h.b = v8;
                    entry = ((ShareRespEntry)v8);
                    v7_1 = new e(this.i, false);
                    ShareAction v1_2 = v3 == 0 ? ShareAction.wx : ShareAction.wxtimeline;
                    e v1_3 = v7_1.a(v1_2).b(v2);
                    if(v3 != 0) {
                        v0_1 = v2;
                    }

                    v0 = v1_3.a(v0_1).c(v5).a(new ShareImageBean(v6_2, false)).a();
                }

                return v0;
            }

        label_25:
            v0 = false;
        }

        return v0;
    }

    public final boolean a() {
        return com.ss.android.article.share.d.h.a(this.i, this.u.isShareExtendedObjectEnabled()).a();
    }

    public static CommonWXShareHelper a(Context arg2, IShareDataHook arg3) {
        Object v1 = s;
        synchronized (v1) {
            if (r == null) {
                r = new CommonWXShareHelper(arg2);
            }

        }
        if (arg3 == null) {
            return r;
        }
        r.u = arg3;
        return r;
    }

    private boolean a(IShareArticleBean arg9, int arg10, ArticleActionHelper arg11) {
        String v3 = null;
        int v2 = 1;
        boolean v1 = false;
        if(arg9 == null) {
            Logger.w("WeixinShareHelper", "shareArticle article is null");
            return v1;
        }

        boolean v0 = !android.support.design.a.isTextEmpty(arg9.getVideoId()) || (arg9.h()) ? true : false;
        this.q = v0;
        this.j = true;
        this.k = arg9.getTitle();
        if(this.mIsWenda) {
            this.k = this.i.getString(com.ss.android.article.browser.R.string.wenda_share_title_format, new Object[]{this.k, this.g, Integer.valueOf(this.h)});
        }
        else if(!android.support.design.a.isTextEmpty(arg9.getMediaName())) {
            this.k = "【" + arg9.getMediaName() + "】" + this.k;
        }

        if(arg10 != 1) {
            v2 = 0;
        }

        String v0_1 = v2 != 0 ? "weixin_moments" : "weixin";
        this.n = arg9.a(v0_1, v0_1);
        this.l = arg9.w();
        if(arg9 != null) {
            v0_1 = arg9.s() != null ? ImageUtils.a(arg9.s()) : v3;
            if((android.support.design.a.isTextEmpty(v0_1)) && arg9.getMiddleImage() != null) {
                v0_1 = ImageUtils.a(arg9.getMiddleImage());
            }

            if((android.support.design.a.isTextEmpty(v0_1)) && arg9.t() != null && arg9.t().size() > 0) {
                v0_1 = ImageUtils.a((ImageInfo) arg9.t().get(0));
            }

            v3 = v0_1;
        }

        this.m = v3;
        JSONObject v1_1 = new JSONObject();
        try {
            UrlBuilder v0_3 = new UrlBuilder("sslocal://detail");
            v0_3.addParam("groupid", arg9.getGroupId());
            v0_3.addParam("item_id", arg9.getItemId());
            v0_3.addParam("aggr_type", arg9.B());
            v0_3.addParam("gd_label", "weixin_app_message");
            v1_1.put("localUrl", v0_3.build());
        }
        catch(JSONException v0_2) {
            Logger.w("WeixinShareHelper", "create Json execption" + v0_2.toString());
        }

        this.o = v1_1.toString();
        int v1_2 = v2 != 0 ? 12 : 11;
        if(arg11 != null && ((arg9 instanceof AbsArticle))) {
            arg11.a(v1_2, (AbsArticle) arg9, this.mAdid);
        }

        this.setArticleRespEntry(arg9, arg10);
        if(this.mIsWenda) {
            entry.eventName = arg9.getWendaEventName();
        }

        com.ss.android.article.share.d.h.b = entry;
        return this.c(arg10);
    }

    private boolean a(IShareEssayBean arg7, int arg8, ArticleActionHelper arg9) {
        int v0 = 1;
        boolean v1 = false;
        if(arg7 == null) {
            Logger.w("WeixinShareHelper", "shareEssay essay is null");
            return v1;
        }

        this.j = false;
        this.k = this.i.getString(com.ss.android.article.browser.R.string.app_name);
        this.l = arg7.d();
        if(arg8 != 1) {
            v0 = 0;
        }

        this.n = arg7.f();
        JSONObject v2 = new JSONObject();
        try {
            UrlBuilder v1_2 = new UrlBuilder("sslocal://essay_detail");
            v1_2.addParam("groupid", arg7.getGroupID());
            v1_2.addParam("gd_label", "weixin_app_message");
            v2.put("localUrl", v1_2.build());
        } catch(JSONException v1_1) {
            Logger.d("WeixinShareHelper", "essay exchange json err" + v1_1.toString());
        }

        this.o = v2.toString();
        if(arg9 != null && ((arg7 instanceof AbsArticle))) {
            int v1_3 = v0 != 0 ? 12 : 11;
            arg9.a(v1_3, (AbsArticle) arg7);
        }

        this.setEssayRespEntry(arg7, arg8);
        return this.c(arg8);
    }

    private boolean a(k arg7, int arg8) {
        boolean v0 = false;
        if(arg7 == null) {
            Logger.w("WeixinShareHelper", "shareForum forumItem is null");
            return v0;
        }

        this.j = false;
        String v0_1 = android.support.design.a.isTextEmpty(arg7.d()) ? this.i.getString(com.ss.android.article.browser.R.string.app_name) : arg7.d();
        this.k = v0_1;
        this.l = arg7.a();
        v0_1 = arg8 == 1 ? this.l : this.k;
        this.k = v0_1;
        this.n = arg7.getShareUrl();
        this.m = arg7.b();
        JSONObject v1 = new JSONObject();
        try {
            UrlBuilder v0_3 = new UrlBuilder("sslocal://forum");
            v0_3.addParam("id", arg7.e());
            v0_3.addParam("gd_label", "weixin_app_message");
            v1.put("localUrl", v0_3.build());
        } catch(Throwable v0_2) {
            Logger.w("WeixinShareHelper", "forum exchange json err " + v0_2);
        }

        this.o = v1.toString();
        this.setForumRespEntry(arg8);
        return this.c(arg8);
    }

    public final void setAdid(long arg2) {
        this.mAdid = arg2;
    }

    public final boolean doAction(Object arg2, Object[] arg3) {
        return this.a(((IShareDataBean)arg2), arg3);
    }

    public final void b() {
        this.mAdid = 0;
        this.mShareSource = 0;
        this.mExtJsonObj = null;
        this.f = null;
        this.p = false;
        this.q = false;
        this.j = false;
        this.k = null;
        this.l = null;
        this.n = null;
        this.m = null;
        this.o = null;
        this.mIsWenda = false;
        this.g = "";
        this.h = 0;
        com.ss.android.article.share.d.h.a(this.i, this.u.isShareExtendedObjectEnabled());
        com.ss.android.article.share.d.h.b();
    }

    public static String b(int arg1) {
        String v0 = arg1 == 0 ? "share_weixin" : "share_weixin_moments";
        return v0;
    }

    private boolean b(IShareEntryItemBean arg9, int arg10) {
        String v3 = null;
        boolean v2 = false;
        if(arg9 == null) {
            Logger.w("WeixinShareHelper", "shareEntryItem entryItem is null");
            return v2;
        }

        this.j = false;
        this.k = this.i.getString(com.ss.android.article.browser.R.string.app_name);
        boolean v0 = Spipe.inst().pgcMediaid == arg9.getId() ? true : false;
        this.p = v0;
        String v0_1 = arg9.getName() != null ? arg9.getName() : v3;
        String v4 = arg9.getDescription() != null ? arg9.getDescription() : v3;
        if(arg9.getShareUrl() != null) {
            v3 = arg9.getShareUrl();
        }

        String v5 = this.p ? this.i.getString(com.ss.android.article.browser.R.string.s5) : this.i.getString(com.ss.android.article.browser.R.string.s6);
        this.l = String.format(v5, v0_1, v4, v3);
        this.n = arg9.getShareUrl();
        this.m = arg9.getIconUrl();
        JSONObject v1 = new JSONObject();
        try {
            UrlBuilder v0_3 = new UrlBuilder("sslocal://media_account");
            v0_3.addParam("entry_id", arg9.getId());
            v0_3.addParam("media_id", arg9.getId());
            v0_3.addParam("gd_label", "weixin_app_message");
            v1.put("localUrl", v0_3.build());
        }
        catch(JSONException v0_2) {
            if(Logger.debug()) {
                Logger.d("WeixinShareHelper", "entryItem exchange json err" + v0_2.toString());
            }
        }

        this.o = v1.toString();
        this.setEntryItemRespEntry(arg9, arg10);
        return this.c(arg10);
    }

    private boolean b(ISharePostBean arg8, int arg9) {
        JSONObject v0 = new JSONObject();
        if(arg8 != null) {
            try {
                v0.put("source", arg8.getId());
            }
            catch(JSONException v0_1) {
            }
        }

        String v0_2 = arg8.getShareUrl();
        String v2 = ShareDemo.a(this.i, arg8);
        String v3 = ShareDemo.a(arg8);
        String v4 = ShareDemo.b(arg8);
        this.setPostRespEntry(arg8, arg9);
        v0_2 = arg9 == 0 ? ShareDemo.a(v0_2, "weixin", "weixin") : ShareDemo.a(v0_2, "weixin_moments", "weixin_moments");
        e v5 = new e(this.i, this.u.isShareExtendedObjectEnabled());
        ShareAction v1 = arg9 == 0 ? ShareAction.wx : ShareAction.wxtimeline;
        v5 = v5.a(v1).b(v3);
        String v1_1 = arg9 == 0 ? v2 : v3;
        return v5.a(v1_1).c(v0_2).a(new ShareImageBean(v4, false)).a();
    }

    private boolean b(IShareUpdateItemBean arg7, int arg8) {
        String v0_1;
        int v5 = 203;
        String v1 = null;
        int v4 = R.string.app_name;
        if(arg7 == null) {
            Logger.w("WeixinShareHelper", "shareUpdateItem updateItem is null");
            boolean v0 = false;
            return v0;
        }

        if(arg7.getItemType() == 200 || arg7.getItemType() == 201) {
            this.k = this.i.getString(v4);
            v0_1 = arg7.h() == null ? this.i.getString(v4) : arg7.h();
            v0_1 = arg7.e() == null ? this.i.getString(v4) : v0_1 + ": " + arg7.e();
            this.l = v0_1;
            this.mShareSource = v5;
        }
        else {
            v0_1 = arg7.h() == null ? this.i.getString(v4) : arg7.h();
            this.k = v0_1;
            v0_1 = arg7.e() == null ? this.i.getString(v4) : arg7.e();
            this.l = v0_1;
            this.mShareSource = v5;
        }

        this.n = arg7.getShareUrl();
        this.j = false;
        ImageInfo v0_2 = (ImageInfo) (arg7.b() == null || arg7.b().size() <= 0 ? v1 : arg7.b().get(0));
        if(v0_2 == null) {
            v0_1 = arg7.c() != null ? arg7.c() : v1;
            v0_2 = new ImageInfo(v0_1, v1);
        }

        this.m = ImageUtils.a(v0_2);
        JSONObject v1_1 = new JSONObject();
        try {
            UrlBuilder v0_5 = new UrlBuilder("sslocal://talk");
            v0_5.addParam("id", arg7.getId());
            v0_5.addParam("gd_label", "weixin_app_message");
            v1_1.put("localUrl", v0_5.build());
        } catch(JSONException v0_4) {
            Logger.w("WeixinShareHelper", "updateItem exchange json err" + v0_4.toString());
        }

        this.o = v1_1.toString();
        this.setUpdateRespEntry(arg7, arg8);
        return this.c(arg8);
    }

    private boolean c(int arg5) {
        boolean v0 = true;
        com.ss.android.article.share.d.h v1 = com.ss.android.article.share.d.h.a(this.i, this.u.isShareExtendedObjectEnabled());
        v1.a = this.j;
        if(arg5 != 1) {
            v0 = false;
        }

        v1.a(v0);
        e v1_1 = new e(this.i, this.u.isShareExtendedObjectEnabled());
        ShareAction v0_1 = arg5 == 0 ? ShareAction.wx : ShareAction.wxtimeline;
        e v0_2 = v1_1.a(v0_1);
        v0_2.a.setExtraString(this.o);
        return v0_2.c(this.n).b(this.l).a(this.k).a(new ShareImageBean(this.m, this.q)).a();
    }
}

